/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ifpb.pp.rh.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Gabriella
 */
//@NamedQueries({@NamedQuery(name="quantidade.servidores.cargo", query="SELECT c.nome,c.classe, COUNT(*) AS total FROM Cargo c JOIN c.servidores s GROUP BY c.nome,c.classe"),
//@NamedQuery(name="servidores.cargo", query="SELECT s.nome, s.matricula FROM Cargo c JOIN c.servidores s WHERE c.nome=?1 ORDER BY s.nome")})
@NamedQueries({@NamedQuery(name="cargo.nome",query="SELECT c FROM Cargo c WHERE c.nome = ?1")})
@Entity
public class Cargo implements Serializable {

    private Integer id;
    private String nome;
    private char classe;
    private List<Servidor> servidores;

    public Cargo() {
        this.inicializar();
    }

    public Cargo(String nome, char classe) {
        this.inicializar();
        this.nome = nome;
        this.classe = classe;
    }

    @Id
    @GeneratedValue
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
   
    @Column(unique=true)
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public char getClasse() {
        return classe;
    }

    public void setClasse(char classe) {
        this.classe = classe;
    }


    @OneToMany(cascade={CascadeType.ALL})
    public List<Servidor> getServidores() {
        return servidores;
    }

    public void setServidores(List<Servidor> servidores) {
        this.servidores = servidores;
    }

     public Boolean addServidores(Servidor servidor){
        if(!this.servidores.contains(servidor))
            return this.servidores.add(servidor);
        return true;
    }

    public Boolean removerServidor(Servidor servidor){
        if(this.servidores.contains(servidor))
            return this.servidores.remove(servidor);
        return true;
    }

    private void inicializar() {
        this.servidores = new ArrayList<Servidor>();

    }




}
